import Vue from 'vue'
import Vuex from 'vuex'
import { userInfo} from "../api/api"

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    isLogin: false,
    userInfo: "",
  },
  mutations: {
    changeLogin(state, payload) {
      state.isLogin = payload.isLogin
      state.userInfo = payload.userInfo

    },
  },
  actions: {
    checkLogin(context) {
      // 个人信息
      userInfo().then(res => {
        console.log(res);
        if (res.code == 0) {
          context.commit("changeLogin", { isLogin: true, userInfo: res.data })
        }
      })

    },
  },
  modules: {
  }
})
